package com.example.stock.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.stock.eo.ProBar399006Eo;
import com.example.stock.eo.ProBar399006Eo;
import com.example.stock.mapper.ProBar006Mapper;
import com.example.stock.mapper.ProBar300Mapper;
import com.example.stock.vo.DataVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.NumberFormat;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: zhuchunfeng
 * @Description
 * @Date: 2021/1/2 14:38
 * Copyright (c) 2019 北京新媒传信科技有限公司
 */

@Service
public class ProBar006Service extends ServiceImpl<ProBar006Mapper, ProBar399006Eo> {

    @Resource
    private ProBar006Mapper proBar006Mapper;

    public List<ProBar399006Eo> getAll(){
        return  proBar006Mapper.selectList(Wrappers.<ProBar399006Eo>lambdaQuery().orderByAsc(ProBar399006Eo::getTradeTime));

    }

    //获取30分钟收盘价
    public List<DataVo> getRowData30(){
        List<ProBar399006Eo> ProBar399006Eos = getAll();
        List<DataVo> collect = ProBar399006Eos.stream()
                .filter(t -> !(t.getTradeTime().getHour() == 9 && t.getTradeTime().getMinute() == 30))
                .map(t -> {
                    DataVo dataVo = new DataVo();
                    dataVo.setTime(t.getTradeTime());
                    dataVo.setBigDecimal(t.getClose());
                    return dataVo;
                }).collect(Collectors.toList());
        return collect;
    }


    public List<DataVo> getRowData60() {
        List<ProBar399006Eo> ProBar399006Eos = getAll();


        List<DataVo> collect1 = ProBar399006Eos.stream()
                .filter(t -> !(t.getTradeTime().getHour() == 9 && t.getTradeTime().getMinute() == 30))
                .filter(t -> Arrays.asList("10:30","11:30","14:00","15:00").contains(t.getTradeTime().format(DateTimeFormatter.ofPattern("HH:mm"))))
                .map(t -> {
                    DataVo dataVo = new DataVo();
                    dataVo.setTime(t.getTradeTime());
                    dataVo.setBigDecimal(t.getClose());
                    return dataVo;
                }).collect(Collectors.toList());
        return collect1;
    }
}
